package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.Setmeal;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {
    /**
     * 插入套餐数据
     * @param setmeal
     */
    void add(Setmeal setmeal);

    /**
     * 插入套餐和检查组关系数据
     * @param id
     * @param checkgroupId
     */
    @Insert("insert into t_setmeal_checkgroup (setmeal_id, checkgroup_id) " +
            "VALUES (#{id},#{checkgroupId})")
    void addSetmealAndCheckGroup(Integer id, Integer checkgroupId);

    /**
     * 根据检查组id查询检查组被关联的套餐数量
     * @param id
     * @return
     */
    @Select("select count(setmeal_id) from t_setmeal_checkgroup where checkgroup_id = #{id}")
    int countByCheckgroupId(Integer id);

    /**
     * 根据id删除套餐数据
     * @param id
     */
    @Delete("delete from t_setmeal where id = #{id}")
    void deleteById(Integer id);

    /**
     * 根据套餐id删除套餐和检查组关系数据
     * @param setmealId
     */
    @Delete("delete from t_setmeal_checkgroup where setmeal_id = #{setmealId}")
    void deleteBySetmealId(Integer setmealId);

    /**
     * 根据id查询套餐数据
     * @param id
     * @return
     */
    @Select("select * from t_setmeal where id = #{id}")
    Setmeal findById(Integer id);

    /**
     * 根据套餐id查询套餐和检查组关系数据
     * @param id
     * @return
     */
    @Select("select tc.* from t_checkgroup tc,t_setmeal_checkgroup tsc " +
            "where tc.id = tsc.checkgroup_id and tsc.setmeal_id = #{id}")
    List<CheckGroup> findCheckGroupBySetmealId(Integer id);

    /**
     * 编辑套餐数据
     * @param setmeal
     */
    void update(Setmeal setmeal);

    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    Page<Setmeal> pageQuery(QueryPageBean queryPageBean);
}
